package com.study.flink.datastream.source.parallel;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.functions.source.RichParallelSourceFunction;

/**
 * 并行Source产生数据
 * @author stephen
 * @create 2019-01-26 11:18
 * @since 1.0.0
 */
public class ParallelSource extends RichParallelSourceFunction<Long> {

    boolean isStop = false;

    @Override
    public void run(SourceContext<Long> sourceContext) throws Exception {
        long i = 0 ;
        while (!isStop){
            sourceContext.collect(i++);
            // 300毫秒产生一条数据
            Thread.sleep(900);
        }
    }

    @Override
    public void cancel() {
        isStop = true;
    }

    @Override
    public void open(Configuration parameters) throws Exception {
        super.open(parameters);
    }

    @Override
    public void close() throws Exception {
        super.close();
    }
}
